package com.summer.campussct.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.summer.campussct.mapper.CampusOrShopMapper;
import com.summer.campussct.pojo.CampusOrShop;
import com.summer.campussct.pojo.Category;
import com.summer.campussct.mapper.CategoryMapper;
import com.summer.campussct.pojo.dto.RestResult;
import com.summer.campussct.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 分类表 服务实现类
 * </p>
 *
 * @author Mr.Chen
 * @since 2024-04-21
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {

    @Resource
    private CategoryMapper categoryMapper;

    @Resource
    private CampusOrShopMapper campusOrShopMapper;

    @Override
    public RestResult home() {
        //1. 获取车辆全部分类列表
        List<Category> vehicleCategoryList = categoryMapper.vehicleTypeList(10);

        //2. 获取校园列表
        List<CampusOrShop> campusList = campusOrShopMapper.campusList(10);
        //3. 获取店铺列表
        List<CampusOrShop> shopList = campusOrShopMapper.shopList(4);
        //3. 封装成map返回
        HashMap<String, Object> map = new HashMap<>();
        map.put("vehicleList", vehicleCategoryList);
        map.put("campusList", campusList);
        map.put("shopList", shopList);
        return RestResult.success(map);
    }

    @Override
    public RestResult brandList(int categoryId) {
        return RestResult.success(categoryMapper.brandListByCategoryId(10, categoryId));
    }

    @Override
    public RestResult getVehicleCategoryList() {
        return RestResult.success(this.list(new LambdaQueryWrapper<Category>()
                .select(Category::getId,Category::getPid, Category::getName)
                .eq(Category::getPid, 0))
        );
    }

    @Override
    public RestResult getCategoryName(long id) {
        Category category = getOne(new LambdaQueryWrapper<Category>()
                .eq(Category::getId, id)
                .select(Category::getName));
        return RestResult.success(category.getName());
    }

    @Override
    public RestResult listPage(Integer categoryId) {
        //1. 获取车辆全部分类列表
        List<Category> vehicleCategoryList = categoryMapper.vehicleTypeList(10);

        //2. 获取校园列表
        List<CampusOrShop> campusList = campusOrShopMapper.campusList(10);

        //3. 获取品牌列表
        List<Category> brandList = categoryMapper.brandListByCategoryId(10, categoryId);

        HashMap<String, Object> map = new HashMap<>();
        map.put("vehicleList", vehicleCategoryList);
        map.put("campusList", campusList);
        map.put("brandList", brandList);
        return RestResult.success(map);
    }
}
